package com.moss.cloud.common.base.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.util.List;
import java.util.Objects;

/**
 * 分页工具
 *
 * @param
 * @author 瑾年
 * @date 2023年4月9日
 */
public class PageUtil {

    public static <T> Page<T> createPage(Long current, Long size) {
        if (Objects.isNull(current)) {
            current = 1L;
        }
        if (Objects.isNull(size)) {
            size = 10L;
        }
        Page<T> page = new Page<>(current, size);
        return page;
    }

    public static <T> IPage<T> ofPage(Long current, Long size, Integer total,Long pages, List<T> records) {
        IPage<T> page = new Page<>();
        page.setCurrent(current);
        page.setSize(size);
        page.setTotal(total);
        page.setPages(pages);
        page.setRecords(records);
        return page;
    }
}
